
main_df <- main_df %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))

attitude1 <- lm(player.post1 ~ factor(pub_official_indicator==1)*factor(group.treatment), data = main_df)
attitude2 <- lm(player.post2 ~ factor(pub_official_indicator==1)*factor(group.treatment), data = main_df)
attitude3 <- lm(player.post3 ~ factor(pub_official_indicator==1)*factor(group.treatment), data = main_df)
attitude4 <- lm(player.post4 ~ factor(pub_official_indicator==1)*factor(group.treatment), data = main_df)
attitude5 <- lm(player.post5 ~ factor(pub_official_indicator==1)*factor(group.treatment), data = main_df)

observations <- c(nobs(attitude1),nobs(attitude2),nobs(attitude3),nobs(attitude4),nobs(attitude5))

attitude1 <- coeftest(attitude1, vcov=vcovHC(attitude1,type="HC0"))
attitude2 <- coeftest(attitude2, vcov=vcovHC(attitude2,type="HC0"))
attitude3 <- coeftest(attitude3, vcov=vcovHC(attitude3,type="HC0"))
attitude4 <- coeftest(attitude4, vcov=vcovHC(attitude4,type="HC0"))
attitude5 <- coeftest(attitude5, vcov=vcovHC(attitude5,type="HC0"))

table <- list(attitude1, attitude2, attitude3, attitude4, attitude5)

note_text <- paste("Beta coefficients from OLS regression. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes quizzed respondents whether (1) they believed the selection process was fair; (2) the public official was the best person
                   for the job; (3) the allocation of money was fair; (4) they were satisfied with what they received; (5) people can be trusted.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Attitudes",
                  label = 'tab:attitudes',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1, 1, 1, 1),
                  column.labels = c("Selection Fair" , "Official Quality", "Allocation Fair", "Satisfied", "Trust"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Observations", observations)),
                  covariate.labels = c("Public Official", "Selection: Merit", "Selection: Patronage", "Public Official X Merit", "Public Official X Patronage"),
                  
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 27, 30, 33, 38)], note_text, './outputs/tables/table_3.tex', .8)

